package com.smile.weather.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.smile.weather.R;
import com.smile.weather.bean.LifeIndexData;
import com.smile.weather.bean.TodayWeatherData;
import com.smile.weather.bean.TwoDayWeatherData;
import com.smile.weather.interfaces.ITodayFragment;
import com.smile.weather.presenter.TodayPresenter;

/**
 * Created by smile on 2016/8/22.
 */
public class TodayFragment extends BaseFragment implements ITodayFragment {

    private View mView;
    // 日期
    private TextView tv_date;
    // 今天的天气
    private TextView tv_today_weather;
    // 今天的温度
    private TextView tv_today_temperature;
    // 左边-日期
    private TextView tv_left_date;
    // 左边-天气
    private TextView tv_left_weather;
    // 左边-温度
    private TextView tv_left_temperature;
    // 左边-风向风力
    private TextView tv_left_wind;
    // 左边-时间
    private TextView tv_left_time;
    // 右边-日期
    private TextView tv_right_date;
    // 右边-天气
    private TextView tv_right_weather;
    // 右边-温度
    private TextView tv_right_temperature;
    // 右边-风向风力
    private TextView tv_right_wind;
    // 右边-时间
    private TextView tv_right_time;
    // 紫外线指数
    private TextView tv_uv_index_value;
    // 紫外线指数-提示
    private TextView tv_uv_index_hint;
    // 感冒指数
    private TextView tv_code_index_value;
    // 感冒指数-提示
    private TextView tv_code_index_hint;
    // 穿衣指数
    private TextView tv_dressing_index_value;
    // 穿衣指数-提示
    private TextView tv_dressing_index_hint;
    // 汽车指数
    private TextView tv_car_index_value;
    // 汽车指数-提示
    private TextView tv_car_index_hint;
    // 运动指数
    private TextView tv_sports_index_value;
    // 运动指数-提示
    private TextView tv_sports_index_hint;
    // 空气污染扩散指数
    private TextView tv_air_pollution_index_value;
    // 空气污染扩散指数-提示
    private TextView tv_air_pollution_index_hint;
    // 相对湿度
    private TextView tv_humidity;
    // 风向
    private TextView tv_wd;
    // 风力
    private TextView tv_ws;
    // PM2.5
    private TextView tv_aqi;
    // 限行
    private TextView tv_limitnumber;

    // 今天天气
    private ImageView iv_today_weather;
    // 左边-天气
    private ImageView iv_left_weather;
    // 左边-时间图标
    private ImageView iv_left_time_icon;
    // 右边-天气
    private ImageView iv_right_weather;
    // 右边-时间图标
    private ImageView iv_right_time_icon;

    private TodayPresenter mTodayPresenter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
            savedInstanceState) {

        mView = inflater.inflate(R.layout.fragment_today_weather, container, false);
        initView();

        return mView;
    }

    /**
     * 初始化视图(控件)
     */
    private void initView() {

        mTodayPresenter = new TodayPresenter(getActivity());
        mTodayPresenter.setiTodayFragment(this);

        tv_date = (TextView) mView.findViewById(R.id.tv_date);
        tv_today_weather = (TextView) mView.findViewById(R.id.tv_today_weather);
        tv_today_temperature = (TextView) mView.findViewById(R.id.tv_today_temperature);
        tv_left_date = (TextView) mView.findViewById(R.id.tv_left_date);
        tv_left_weather = (TextView) mView.findViewById(R.id.tv_left_weather);
        tv_left_temperature = (TextView) mView.findViewById(R.id.tv_left_temperature);
        tv_left_wind = (TextView) mView.findViewById(R.id.tv_left_wind);
        tv_left_time = (TextView) mView.findViewById(R.id.tv_left_time);
        tv_right_date = (TextView) mView.findViewById(R.id.tv_right_date);
        tv_right_weather = (TextView) mView.findViewById(R.id.tv_right_weather);
        tv_right_temperature = (TextView) mView.findViewById(R.id.tv_right_temperature);
        tv_right_wind = (TextView) mView.findViewById(R.id.tv_right_wind);
        tv_right_time = (TextView) mView.findViewById(R.id.tv_right_time);
        tv_uv_index_value = (TextView) mView.findViewById(R.id.tv_uv_index_value);
        tv_uv_index_hint = (TextView) mView.findViewById(R.id.tv_uv_index_hint);
        tv_code_index_value = (TextView) mView.findViewById(R.id.tv_code_index_value);
        tv_code_index_hint = (TextView) mView.findViewById(R.id.tv_code_index_hint);
        tv_dressing_index_value = (TextView) mView.findViewById(R.id.tv_dressing_index_value);
        tv_dressing_index_hint = (TextView) mView.findViewById(R.id.tv_dressing_index_hint);
        tv_car_index_value = (TextView) mView.findViewById(R.id.tv_car_index_value);
        tv_car_index_hint = (TextView) mView.findViewById(R.id.tv_car_index_hint);
        tv_sports_index_value = (TextView) mView.findViewById(R.id.tv_sports_index_value);
        tv_sports_index_hint = (TextView) mView.findViewById(R.id.tv_sports_index_hint);
        tv_air_pollution_index_value = (TextView) mView.findViewById(R.id.tv_air_pollution_index_value);
        tv_air_pollution_index_hint = (TextView) mView.findViewById(R.id.tv_air_pollution_index_hint);
        tv_humidity = (TextView) mView.findViewById(R.id.tv_humidity);
        tv_wd = (TextView) mView.findViewById(R.id.tv_wd);
        tv_ws = (TextView) mView.findViewById(R.id.tv_ws);
        tv_aqi = (TextView) mView.findViewById(R.id.tv_aqi);
        tv_limitnumber = (TextView) mView.findViewById(R.id.tv_limitnumber);

        iv_today_weather = (ImageView) mView.findViewById(R.id.iv_today_weather);
        iv_left_weather = (ImageView) mView.findViewById(R.id.iv_left_weather);
        iv_left_time_icon = (ImageView) mView.findViewById(R.id.iv_left_time_icon);
        iv_right_weather = (ImageView) mView.findViewById(R.id.iv_right_weather);
        iv_right_time_icon = (ImageView) mView.findViewById(R.id.iv_right_time_icon);

    }

    @Override
    public void setTodayWeather(TodayWeatherData todayWeather) {
        //设置日期
        tv_date.setText(todayWeather.getDate());
        //设置今天天气
        tv_today_weather.setText(todayWeather.getWeather());
        //设置今天温度
        tv_today_temperature.setText(todayWeather.getTemp());
        //设置今天天气图标
        iv_today_weather.setImageResource(getResources().getIdentifier(todayWeather.getWeathercode(), "drawable",
                "com.smile.weather"));
        //设置相对湿度
        tv_humidity.setText(todayWeather.getSD());
        //设置风向
        tv_wd.setText(todayWeather.getWD());
        //设置风力
        tv_ws.setText(todayWeather.getWS());
        //设置PM2.5
        tv_aqi.setText(todayWeather.getAqi_pm25());
        //设置限行
        tv_limitnumber.setText(todayWeather.getLimitnumber());
    }

    @Override
    public void setTwoDayWeather(TwoDayWeatherData[] twoDayWeather) {
        //设置左边日期
        tv_left_date.setText(twoDayWeather[0].getDate());
        //设置左边天气图标
        iv_left_weather.setImageResource(getResources().getIdentifier(twoDayWeather[0].getWeather_icon(), "drawable",
                "com.smile.weather"));
        //设置左边天气
        tv_left_weather.setText(twoDayWeather[0].getWeather());
        //设置左边温度
        tv_left_temperature.setText(twoDayWeather[0].getTemperature());
        //设置左边风
        tv_left_wind.setText(twoDayWeather[0].getWind());
        //设置左边时间图标
        iv_left_time_icon.setImageResource(getResources().getIdentifier(twoDayWeather[0].getTime_icon(), "drawable",
                "com.smile.weather"));
        //设置左边时间
        tv_left_time.setText(twoDayWeather[0].getTime());
        //---------------------------------------------------
        //设置右边日期
        tv_right_date.setText(twoDayWeather[1].getDate());
        //设置左边天气图标
        iv_right_weather.setImageResource(getResources().getIdentifier(twoDayWeather[1].getWeather_icon(), "drawable",
                "com.smile.weather"));
        //设置左边天气
        tv_right_weather.setText(twoDayWeather[1].getWeather());
        //设置左边温度
        tv_right_temperature.setText(twoDayWeather[1].getTemperature());
        //设置左边风
        tv_right_wind.setText(twoDayWeather[1].getWind());
        //设置左边时间图标
        iv_right_time_icon.setImageResource(getResources().getIdentifier(twoDayWeather[1].getTime_icon(), "drawable",
                "com.smile.weather"));
        //设置左边时间
        tv_right_time.setText(twoDayWeather[1].getTime());
    }

    @Override
    public void setLifeIndex(LifeIndexData lifeIndex) {
        //设置紫外线指数
        tv_uv_index_value.setText(lifeIndex.getUv_index()[0]);
        tv_uv_index_hint.setText(lifeIndex.getUv_index()[1]);
        //设置感冒指数
        tv_code_index_value.setText(lifeIndex.getCode_index()[0]);
        tv_code_index_hint.setText(lifeIndex.getCode_index()[1]);
        //设置穿衣指数
        tv_dressing_index_value.setText(lifeIndex.getDressing_index()[0]);
        tv_dressing_index_hint.setText(lifeIndex.getDressing_index()[1]);
        //设置汽车指数
        tv_car_index_value.setText(lifeIndex.getCar_index()[0]);
        tv_car_index_hint.setText(lifeIndex.getCar_index()[1]);
        //设置运动指数
        tv_sports_index_value.setText(lifeIndex.getSports_index()[0]);
        tv_sports_index_hint.setText(lifeIndex.getSports_index()[1]);
        //设置空气污染扩散指数
        tv_air_pollution_index_value.setText(lifeIndex.getAir_pollution_index()[0]);
        tv_air_pollution_index_hint.setText(lifeIndex.getAir_pollution_index()[1]);
    }

    @Override
    public void setHtml(String html) {
        Log.i("tf", "html--" + html);
        mTodayPresenter.analyzeHtml(html);
    }
}
